/**
 * 
 */
package com.chinamobile.maps.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.chinamobile.maps.dao.IAccesslogsDAO;
import com.chinamobile.maps.orm.Accesslogs;
import com.chinamobile.maps.orm.Users;

/**
 * @author FrankWong
 *
 */
public class AccesslogsDAOImpl extends HibernateDaoSupport implements
		IAccesslogsDAO {

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IAccesslogsDAO#addAccesslogs(com.chinamobile.maps.orm.Accesslogs)
	 */
	@Override
	public void addAccesslogs(Accesslogs accesslogs) {
		this.getHibernateTemplate().save(accesslogs);
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IAccesslogsDAO#delAccesslogs(com.chinamobile.maps.orm.Accesslogs)
	 */
	@Override
	public void delAccesslogs(Accesslogs accesslogs) {
		this.getHibernateTemplate().delete(accesslogs);
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IAccesslogsDAO#delAccesslogs(int)
	 */
	@Override
	public void delAccesslogs(int id) {
		this.getHibernateTemplate().delete(getAccesslogsById(id));
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IAccesslogsDAO#updateAccesslogs(com.chinamobile.maps.orm.Accesslogs)
	 */
	@Override
	public void updateAccesslogs(Accesslogs accesslogs) {
		this.getHibernateTemplate().update(accesslogs);
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IAccesslogsDAO#getAccesslogs()
	 */
	@Override
	public List<Accesslogs> getAccesslogs() {
		List list = this.getHibernateTemplate().find("from Accesslogs order by createdAt desc");
		if (list != null && list.size() > 0) {
			return list;
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IAccesslogsDAO#getAccesslogsById(int)
	 */
	@Override
	public Accesslogs getAccesslogsById(int id) {
		List list = this.getHibernateTemplate().find("from Accesslogs as accesslogs where accesslogs.id=?",
				new Object[] { id });

		if (list != null && list.size() > 0) {
			return (Accesslogs) list.get(0);
		}
		return null;
	}

}
